<template>
	<view>
		<wuc-tab id="tab" :tab-list="tabList3" textFlex :tabCur.sync="TabCur3" tab-class="text-center text-black bg-white wuc-tab fixed"
		 select-class="text-blue" @change="tabChange"></wuc-tab>
		<scroll-view scroll-y :style="{height:(height-51)+'px'}">
			<view v-if="TabCur3==0">
				<view class="search-input "><label class="iconfont icon-sousuo" />
					<input type="text" v-model="search" confirm-type="search" class="font-size30" placeholder="搜索" /></view>
				<view class="list" v-if="sendLogList.length">
					<uni-swipe-action>
						<uni-swipe-action-item v-for="(item,index) in sendLogList" :options="options" :key="index" @click="removeSendLog(item,index)">
							<view class="item" @click.stop="workLogInfo(item)">
								<view class="uni-list-cell uni-list-cell-last" hover-class="uni-list-cell-hover">
									<view class="cell-navigate">
										<view class="uni-item-left">
											<view class="uni-item-left-name font-size30 color-3A3A3A">{{item.F_Title}}</text></view>
											<view class="font-size24 color-9A9A9A">{{item.F_UserName}}</view>
										</view>
										<view class="uni-item-right">
											<view class="font-size24 color-9A9A9A">{{item.F_CreatorTime}}</view>
											<view class="height-50"></view>
										</view>
									</view>
								</view>
							</view>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
				<view class="noContent" v-show="isNoData">
					<img :src="nodata" alt="">
					<view class="">
						暂无数据
					</view>
				</view>
			</view>
			<view v-if="TabCur3==1" class="example-body">
				<view class="search-input "><label class="iconfont icon-sousuo" />
					<input type="text" v-model="search" confirm-type="search" class="font-size30" placeholder="搜索" /></view>
				<view v-if="receiveLogList.length" class="list">
					<uni-swipe-action>
						<uni-swipe-action-item v-for="(item,index) in receiveLogList" :options="options" :key="index" @click="removeReceiveLog(item,index)">
							<view class="item" @click.stop="workLogInfo(item)">
								<view class="uni-list-cell uni-list-cell-last" hover-class="uni-list-cell-hover">
									<view class="cell-navigate">
										<view class="uni-item-left">
											<view class="uni-item-left-name font-size30 color-3A3A3A">{{item.F_Title}}</text></view>
											<view class="font-size24 color-9A9A9A">{{item.F_UserName}}</view>
										</view>
										<view class="uni-item-right">
											<view class="font-size24 color-9A9A9A">{{item.F_CreatorTime}}</view>
											<view class="height-50"></view>
										</view>
									</view>
								</view>
							</view>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
				<view class="noContent" v-show="isNoDataRe">
					<img :src="nodata" alt="">
					<view class="">
						暂无数据
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 新增按钮 -->
		<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction" @creqateopen="creqateopen"></uni-fab>
	</view>
</template>

<script>
	import helper from '@/common/js/helper.js'
	import jnpf from '@/common/js/jnpf.js'
	import uniFab from '@/components/uni-fab/uni-fab.vue'
	import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue'
	import WucTab from '@/components/wuc-tab/wuc-tab.vue';
	import config from '@/common/js/config.js'
	export default {
		data() {
			return {
				search: '',
				rows: 15,
				page: 1,
				total: 1,
				height: 0,
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: "#007AFF"
				},
				tabList3: [{
					name: '我发出的'
				}, {
					name: '我收到的'
				}],
				receiveList: [],
				sendList: [],
				nodata: config.Resources.message.nodata,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				TabCur3: 0,
				isNoData: false,
				isNoDataRe: false,
			}
		},
		computed: {
			sendLogList: function() {
				let sendList = this.sendList;
				let search = this.search;
				if (search) {
					return sendList.filter(function(product) {
						return Object.keys(product).some(function(key) {
							return String(product[key]).toLowerCase().indexOf(search) > -1
						})
					})
				}
				return sendList
			},
			receiveLogList: function() {
				let receiveList = this.receiveList;
				let search = this.search;
				if (search) {
					return receiveList.filter(function(product) {
						return Object.keys(product).some(function(key) {
							return String(product[key]).toLowerCase().indexOf(search) > -1
						})
					})
				}
				return receiveList
			}
		},
		onShow() {
			this.sendList.length = 0;
			this.initSend();
			this.receiveList.length = 0;
			this.isNoData = false;
			this.isNoDataRe = false;
			this.initReceive();
			this.$forceUpdate();
		},
		methods: {
			tabChange(index) {
				this.search = '';
				this.TabCur3 = index;
				uni.setStorageSync("TabCur3",this.TabCur3)
			},
			scrollButtonSend() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				let _this = this;
				if (_this.total > _this.page) {
					_this.page += 1;
					//触发求
					helper.ajax({
						url: '/api/Extend/WorkLog/Send',
						method: 'GET',
						data: {
							pageSize: _this.rows, //每页行数
							currentPage: _this.page, //当前页
						},
						success: res => {
							let _total = Math.ceil(res.data.data.pagination.total/res.data.data.pagination.pageSize)
							this.total = _total;
							let _sendList = res.data.data.list;
							for (let i = 0; i < _sendList.length; i++) {
								this.sendList.push({
									'F_Id': _sendList[i].id,
									'F_Title': _sendList[i].title,
									'F_Question': _sendList[i].question,
									'F_CreatorTime': helper.toDate(_sendList[i].creatorTime, 'MM-dd'),
									'F_TodayContent': _sendList[i].todayContent,
									'F_TomorrowContent': _sendList[i].tomorrowContent,
									'F_ToUserId': _sendList[i].toUserId,
									'F_UserName': jnpf.userInfo().realName + '/' + jnpf.userInfo().account
								});
							}
						}
					});
				}
				uni.hideLoading();
			},
			initSend() {
				let _this = this;
				helper.ajax({
					url: '/api/Extend/WorkLog/Send',
					data: {
						pageSize: _this.rows, //每页行数
						currentPage: 1, //当前页
					},
					success: res => {
						this.page = 1;
						let _total = Math.ceil(res.data.data.pagination.total/res.data.data.pagination.pageSize)
						this.total = _total;
						let _sendList = res.data.data.list;
						this.isNoData = _sendList.length > 0 ? false : true;
						for (let i = 0; i < _sendList.length; i++) {
							this.sendList.push({
								'F_Id': _sendList[i].id,
								'F_Title': _sendList[i].title,
								'F_Question': _sendList[i].question,
								'F_CreatorTime': helper.toDate(_sendList[i].creatorTime, 'MM-dd'),
								'F_TodayContent': _sendList[i].todayContent,
								'F_TomorrowContent': _sendList[i].tomorrowContent,
								'F_ToUserId': _sendList[i].toUserId,
								'F_UserName': jnpf.userInfo().realName + '/' + jnpf.userInfo().account
							});
						}
					}
				});
			},
			scrollButtonReceive() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				let _this = this;
				if (_this.total > _this.page) {
					_this.page += 1;
					//触发求
					helper.ajax({
						url: '/api/Extend/WorkLog/Receive',
						method: 'GET',
						data: {
							pageSize: _this.rows, //每页行数
							currentPage: _this.page, //当前页
						},
						success: res => {
							let _total = Math.ceil(res.data.data.pagination.total/res.data.data.pagination.pageSize)
							this.total = _total;
							let _receiveList = res.data.data.list;
							for (let i = 0; i < _receiveList.length; i++) {
								this.receiveList.push({
									'F_Id': _receiveList[i].id,
									'F_Title': _receiveList[i].title,
									'F_Question': _receiveList[i].question,
									'F_CreatorTime': helper.toDate(_receiveList[i].creatorTime, 'MM-dd'),
									'F_TodayContent': _receiveList[i].todayContent,
									'F_TomorrowContent': _receiveList[i].tomorrowContent,
									'F_ToUserId': _receiveList[i].toUserId,
									'F_UserName': jnpf.userInfo().realName + '/' + jnpf.userInfo().account
								});
							}
						}
					});
				}
				uni.hideLoading();
			},
			initReceive() {
				let _this = this;
				helper.ajax({
					url: '/api/Extend/WorkLog/Receive',
					data: {
						pageSize: _this.rows, //每页行数
						currentPage: 1, //当前页
					},
					success: res => {
						this.page = 1;
						let _total = Math.ceil(res.data.data.pagination.total/res.data.data.pagination.pageSize)
						this.total = _total;
						let _receiveList = res.data.data.list;
						this.isNoDataRe = _receiveList.length > 0 ? false : true;
						for (let i = 0; i < _receiveList.length; i++) {
							this.receiveList.push({
								'F_Id': _receiveList[i].id,
								'F_Title': _receiveList[i].title,
								'F_Question': _receiveList[i].question,
								'F_CreatorTime': helper.toDate(_receiveList[i].creatorTime, 'MM-dd'),
								'F_TodayContent': _receiveList[i].todayContent,
								'F_TomorrowContent': _receiveList[i].tomorrowContent,
								'F_ToUserId': _receiveList[i].toUserId,
								'F_UserName': jnpf.userInfo().realName + '/' + jnpf.userInfo().account
							});
						}
					}
				});
			},
			creqateopen() {
				uni.navigateTo({
					url: './form'
				})
			},
			removeSendLog(item, index) {
				// console.log(item);
				helper.ajax({
					url: '/api/Extend/WorkLog/' + item.F_Id,
					method: 'Delete',
					success: res => {
						this.sendLogList.splice(index, 1);
						if(this.receiveLogList.length == 0){
							this.isNoData = true;
						}
						helper.msg(res.data.msg, 'success');
					}
				});
			},
			removeReceiveLog(item, index) {
				helper.ajax({
					url: '/api/Extend/WorkLog/' + item.F_Id,
					method: 'Delete',
					success: res => {
						this.receiveLogList.splice(index, 1);
						if(this.receiveLogList.length == 0){
							this.isNoDataRe = true;
						}
						helper.msg(res.data.msg, 'success');
					}
				});
			},
			workLogInfo(e) {
				uni.navigateTo({
					url: './form?id=' + e.F_Id
				})
				
			}
		},
		mounted() {
			let _this = this;
			// 获取设备宽度
			uni.getSystemInfo({
				success: function(res) {
					_this.height = res.windowHeight;
				}
			});
		},
		components: {
			uniFab,
			uniSwipeAction,
			uniSwipeActionItem,
			WucTab
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f2f6;
	}

	.search-input {
		background: #FFFFFF;
	}

	.list {
		padding: 0 20upx;

		.item {
			width: 100%;
			box-shadow: 0px 3px 25px 2px rgba(159, 159, 159, 0.1);
			border-radius: 10upx;

			.item-content {
				padding: 0 20upx;
			}

			.cell-navigate::after {
				height: 0;
			}
		}
	}
</style>
